<?php

namespace app\admin\model\jdy;

use think\Model;

class Devicealarmset extends Model
{
    // 表名
    protected $name = 'jdy_devicealarmset';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'warning_type_text',
        'warning_status_text',
        'delay_time_text',
        'replay_time_text',
        'warning_switch_text',
        'warning1_status_text',
        'warning_way_text',
        'd0_standard_switch_text',
        'd1_standard_switch_text',
        'd2_standard_switch_text',
        'd3_standard_switch_text',
        'd4_standard_switch_text',
        'd5_standard_switch_text',
        'd6_standard_switch_text'
    ];
    

    
    public function getWarningTypeList()
    {
        return ['即時告警' => __('即時告警'),'延時告警' => __('延時告警')];
    }     

    public function getWarningStatusList()
    {
        return ['在線' => __('在線'),'離線' => __('離線')];
    }     

    public function getWarningSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getWarning1StatusList()
    {
        return ['在線' => __('在線'),'離線' => __('離線')];
    }     

    public function getWarningWayList()
    {
        return ['一般設置' => __('一般設置'),'進階設置' => __('進階設置')];
    }     

    public function getD0StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getD1StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getD2StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getD3StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getD4StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getD5StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     

    public function getD6StandardSwitchList()
    {
        return ['開啟' => __('開啟'),'關閉' => __('關閉')];
    }     


    public function getWarningTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['warning_type']) ? $data['warning_type'] : '');
        $list = $this->getWarningTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getWarningStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['warning_status']) ? $data['warning_status'] : '');
        $list = $this->getWarningStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDelayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['delay_time']) ? $data['delay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReplayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['replay_time']) ? $data['replay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getWarningSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['warning_switch']) ? $data['warning_switch'] : '');
        $list = $this->getWarningSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getWarning1StatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['warning1_status']) ? $data['warning1_status'] : '');
        $list = $this->getWarning1StatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getWarningWayTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['warning_way']) ? $data['warning_way'] : '');
        $list = $this->getWarningWayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD0StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d0_standard_switch']) ? $data['d0_standard_switch'] : '');
        $list = $this->getD0StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD1StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d1_standard_switch']) ? $data['d1_standard_switch'] : '');
        $list = $this->getD1StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD2StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d2_standard_switch']) ? $data['d2_standard_switch'] : '');
        $list = $this->getD2StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD3StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d3_standard_switch']) ? $data['d3_standard_switch'] : '');
        $list = $this->getD3StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD4StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d4_standard_switch']) ? $data['d4_standard_switch'] : '');
        $list = $this->getD4StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD5StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d5_standard_switch']) ? $data['d5_standard_switch'] : '');
        $list = $this->getD5StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getD6StandardSwitchTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['d6_standard_switch']) ? $data['d6_standard_switch'] : '');
        $list = $this->getD6StandardSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setDelayTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setReplayTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function device()
    {
        return $this->belongsTo('Device', 'device_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
